package com.jc.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;
public class DateTimeUtil extends DateUtils {
	
	public static final String LONG_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

	public static final String	DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS_SSS	= "yyyy-MM-dd HH:mm:ss:SSS";
	
	
	
	
	/****
	 * 获取当前时间的YY-MM-DD格式
	 * @return
	 */
	public static String getDate(String format) {
		java.text.DateFormat f = new java.text.SimpleDateFormat(format);
	    return f.format(new Date());
	}
	
	public static String getDate(Date date,String format) {
		java.text.DateFormat f = new java.text.SimpleDateFormat(format);
		return f.format(date);
	}
	
	public static Date  getDateByString(String date,String format) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.parse(date);
	}
	/***
	 * 
	 * @param date   原始日期
	 * @param offset 偏移量
	 * @return 返回天偏移后的Date
	 */
	public static Date addDay(Date date,int offset) {
		 Calendar c = Calendar.getInstance();  
         c.setTime(date);  
         c.add(Calendar.DAY_OF_MONTH, offset);  
         return c.getTime();
	}
	
	
	public static Date addMinute(Date date,int offset) {
		 Calendar c = Calendar.getInstance();  
        c.setTime(date);  
        c.add(Calendar.MINUTE, offset);  
        return c.getTime();
	}
	
	
	/***
	 * 
	 * @param date
	 * @param offset
	 * @param format
	 * @return
	 */
	public static String addDay(Date date,int offset,String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(addDay(date,offset));
	}
	
	public static void main(String args[]) {
		
		
	}
	
}
